import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_audio_ctr.dart';
import 'package:xindong/models/user/xindong_kongjian_user.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/widgets/xindong_biaoqian_view.dart';

class XinDongKongJianInfo extends StatelessWidget {
  final XinDongSpaceUser model;

  const XinDongKongJianInfo({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 125,
      color: DZColors.cellColor,
      padding: const EdgeInsets.only(left: 15, top: 10),
      child: Stack(
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                model.getName,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.w600,
                  color: model.is_noble == 1 ? Colors.red : DZColors.titleColor,
                ),
              ),
              const SizedBox(height: 10),
              XinDongBiaoQianList(user: model),
              const SizedBox(height: 18),
              Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      Clipboard.setData(ClipboardData(text: model.uid));
                      showToast("已复制ID");
                    },
                    behavior: HitTestBehavior.opaque,
                    child: Text.rich(
                      TextSpan(text: "ID: ${model.uid}  ·  ", children: [
                        if (model.isSelf == false)
                          TextSpan(
                            text: "${XinDongKongJianCtr.to.distanceText}  ·  ",
                          ),
                        TextSpan(
                          text: "被心动${model.heart ?? 0}",
                        ),
                        if (model.isMale)
                          TextSpan(
                            text: " · 金币${model.volley ?? 0}",
                          ),
                      ]),
                      maxLines: 1,
                      style: const TextStyle(fontSize: 13, color: DZColors.placeholderColor, height: 1.2),
                    ),
                  ),
                ],
              ),
            ],
          ),

          /// 关注按钮
          Positioned(
            top: 10,
            right: 15,
            child: GetBuilder<XinDongKongJianCtr>(
              id: XinDongKongJianCtr.updateIdLoadingInfo,
              builder: (controller) {
                String text = controller.userspace?.love == 1 ? AssetsRes.BUTTON_FOLLOWED : AssetsRes.BUTTON_FOLLOW;
                return GestureDetector(
                  onTap: () => controller.requestAttention(),
                  behavior: HitTestBehavior.opaque,
                  child: SizedBox(
                    width: 87.0,
                    height: 31.0,
                    child: ImageUtil.asset(text),
                  ),
                );
              },
            ),
          ),

          /// 语音简介
          if (!TextUtil.isEmpty(model.voice))
            Positioned(
              bottom: 26,
              right: 0,
              child: Container(
                height: 35,
                padding: const EdgeInsets.only(right: 16),
                decoration: BoxDecoration(
                  color: DZColors.hexStringColor("#FBEDFE"),
                  borderRadius: const BorderRadius.only(topLeft: Radius.circular(35), bottomLeft: Radius.circular(35)),
                ),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const SizedBox(width: 10),
                    GetBuilder<XinDongAudioCtr>(builder: (controller) {
                      bool isPlaying = controller.isPlaying && model.voice == controller.playUrl;
                      return GestureDetector(
                        onTap: () => controller.play(model.voice ?? ""),
                        behavior: HitTestBehavior.opaque,
                        child: ImageUtil.asset(
                          isPlaying ? AssetsRes.BUTTON_YUYIN_PAUSE : AssetsRes.BUTTON_YUYIN_PLAY,
                          width: 19,
                          height: 19,
                        ),
                      );
                    }),
                    const SizedBox(width: 5),
                    Text(
                      "${model.voice_time}″  ",
                      style: const TextStyle(fontSize: 14, color: DZColors.mainColor),
                    ),
                    GestureDetector(
                      onTap: () => XinDongKongJianCtr.to.requestVoiceZan(),
                      behavior: HitTestBehavior.opaque,
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          ImageUtil.asset(
                            model.has_voice_zan == 1 ? AssetsRes.ICON_VOICE_LIKE1 : AssetsRes.ICON_VOICE_LIKE0,
                            width: 16,
                            height: 16,
                          ),
                          const SizedBox(width: 2),
                          Text(
                            "${model.voice_zan}",
                            style: const TextStyle(fontSize: 12, color: DZColors.mainColor, height: 1.2),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),
            )
        ],
      ),
    );
  }
}
